<template>
  <view class="web-view">
    <web-view v-if="locationUrl" :src="locationUrl"></web-view>
    <view class="setup-container" v-else>
      <text class="setup-tip">请先上传配置文件/选择智能体</text>

      <button class="setup-btn" @click="gotoSetup">
        <text class="btn-text">前往设置</text>
      </button>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      locationUrl: null,
    }
  },
  onShow: function () {
    this.locationUrl = uni.getStorageSync('locationUrlItem')
      ? uni.getStorageSync('locationUrlItem').url
      : null
  },
  methods: {
    gotoSetup() {
      uni.switchTab({
        url: '/pages/Setup/index',
        success: () => {
          console.log('切换到 Tab 页面')
        },
        fail: (error) => {
          console.log('切换失败', error)
        },
      })
    },
  },
}
</script>

<style lang="scss" scoped>
.web-view {
  height: 100%;
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}

.setup-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  margin-top: 50px;
}

.setup-tip {
  font-size: 16px;
  color: #666;
  font-weight: 500;
}

.setup-btn {
  width: 200px;
  height: 50px;
  background-color: #007aff;
  color: white;
  border-radius: 25px;
  display: flex;
  justify-content: center;
  align-items: center;
  box-shadow: 0 4px 8px rgba(0, 122, 255, 0.2);
  transition: all 0.3s;
  border: none;

  &:active {
    transform: scale(0.98);
    box-shadow: 0 2px 4px rgba(0, 122, 255, 0.2);
  }

  .btn-text {
    font-size: 16px;
    font-weight: 500;
  }
}
</style>
